#include "Complex.h"

#include <cppunit/TestCase.h>
#include <cppunit/TestFixture.h>
#include <cppunit/TestSuite.h>
#include <cppunit/TestCaller.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/ui/text/TestRunner.h>

class ComplexSimpleTest : public CppUnit::TestCase
{
public:
	ComplexSimpleTest() : CppUnit::TestCase() {}

	virtual void runTest()
	{
		CPPUNIT_ASSERT( Complex( 10, 1 ) == Complex( 10, 1 ) );
		CPPUNIT_ASSERT( !(Complex( 1, 1 ) == Complex( 2, 2 )) );
	}

	CPPUNIT_TEST_SUITE( ComplexSimpleTest );
	CPPUNIT_TEST( runTest );
	CPPUNIT_TEST_SUITE_END();
};

class ComplexFixtureTest : public CppUnit::TestFixture
{
private:
	Complex *m_10_1, *m_1_1, *m_11_2;

public:
	virtual void setUp( void )
	{
		m_10_1 = new Complex( 10, 1 );
		m_1_1 = new Complex( 1, 1 );
		m_11_2 = new Complex( 11, 2 );
	}

	virtual void tearDown( void )
	{
		delete m_10_1;
		delete m_1_1;
		delete m_11_2;
	}

	void testEquality( void )
	{
		CPPUNIT_ASSERT( *m_10_1 == *m_10_1 );
		CPPUNIT_ASSERT( !(*m_10_1 == *m_11_2) );
	}

	void testAddition( void )
	{
		CPPUNIT_ASSERT( *m_10_1 + *m_1_1 == *m_11_2 );
	}

	/*
	static CppUnit::TestSuite *suite( void )
	{
		CppUnit::TestSuite *s = new CppUnit::TestSuite( "ComplexFixtureTest" );

		s->addTest( new CppUnit::TestCaller< ComplexFixtureTest >( "testEquality", &ComplexFixtureTest::testEquality ) );
		s->addTest( new CppUnit::TestCaller< ComplexFixtureTest >( "testAddition", &ComplexFixtureTest::testAddition ) );
		return s;
	}
	*/

	CPPUNIT_TEST_SUITE( ComplexFixtureTest );
	CPPUNIT_TEST( testEquality );
	CPPUNIT_TEST( testAddition );
	CPPUNIT_TEST_SUITE_END();
};

int main( int argc, char *argv[] )
{
	CppUnit::TextUi::TestRunner runner;

	// runner.addTest( new ComplexSimpleTest() );
	runner.addTest( ComplexSimpleTest::suite() );
	runner.addTest( ComplexFixtureTest::suite() );

	return !runner.run();
}

